package cn.juque.redoctopus.client.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author nuoka
 * @version 1.0.0
 * <li>IntelliJ IDEA</li>
 * <li>com.ipukr.wants.cloud.applet.juque.config</li>
 * @date 2021/4/24 19:53
 **/
@Slf4j
@Configuration
public class TopicRabbitConfig {

    @Value("${spring.rabbitmq.topic-exchange}")
    private String topicExchange;

    @Bean
    public Binding bindingExchangeMessage1(@Qualifier("logTopicExchange") TopicExchange topicExchange){
        log.info("init octopus queue one successful");
        return BindingBuilder.bind(logQueue1()).to(topicExchange).with("octopus.log1.#");
    }

    @Bean
    public Binding bindingExchangeMessage2(@Qualifier("logTopicExchange") TopicExchange topicExchange){
        log.info("init octopus queue two successful");
        return BindingBuilder.bind(logQueue2()).to(topicExchange).with("octopus.log2.#");
    }

    private Queue logQueue1() {
        return new Queue("octopus.log1");
    }

    private Queue logQueue2() {
        return new Queue("octopus.log2");
    }

    @Bean("logTopicExchange")
    public TopicExchange logExchange(){
        log.info("init octopus topic exchange successful");
        return new TopicExchange(topicExchange);
    }
}
